package com.sdcx.agrobank.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.sdcx.agrobank.R;
import com.sdcx.agrobank.adapter.MingxiAdapter;
import com.sdcx.agrobank.bean.MingXIBean;
import com.sdcx.agrobank.event.removeEvent;
import com.sdcx.agrobank.event.tjEvent;
import com.sdcx.agrobank.ui.my_activity.jiluActivity;
import com.sdcx.agrobank.util.ACache;
import com.sdcx.agrobank.util.ListDataSave;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MingxiActivity extends AppCompatActivity {

    private RecyclerView rec;
    private ImageView tianjia, back;
    public static ArrayList<MingXIBean> list;
    private MingxiAdapter adapter;
    private ACache cache;

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onmyEvent(tjEvent myEvent) {
        adapter.notifyDataSetChanged();

    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onmyEvent(removeEvent myEvent) {
        adapter.notifyDataSetChanged();


    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mingxi);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        cache = ACache.get(this);
        list = new ArrayList<>();
        rec = findViewById(R.id.rec);
        tianjia = findViewById(R.id.tianjia);
        back = findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

       //list.add(new MingXIBean("支付宝（支付宝-理..", "2020-11-15", "2", "26.01"));
       //list.add(new MingXIBean("支付宝（支付宝-理..", "2020-11-15", "2", "24.01"));


        //cache.put("data",list);
        ListDataSave save = new ListDataSave(MingxiActivity.this, "list");
        List<MingXIBean> lists = save.getDataList("datas");
        for (int i=0;i<lists.size();i++){
            list.add((MingXIBean) lists.get(i));
        }

        Log.e("11111111", list.toString());

        //MingxiActivity.list =lists;
      //  MingxiActivity.list = save.getDataList("datas");

        rec.setLayoutManager(new LinearLayoutManager(this));
        adapter = new MingxiAdapter(this, list);
        rec.setAdapter(adapter);
        tianjia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MingxiActivity.this, jiluActivity.class));
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}